"""
filter
Administrator
2023/12/6
convergence-server
"""
from django_filters import FilterSet, filters, rest_framework

from medias.models import MediaContent, Image


class MediasFilter(FilterSet):
    """媒体过滤"""
    title = filters.CharFilter(field_name='title', lookup_expr="icontains", label="媒体标题")
    # sku = filters.CharFilter(field_name='sku__title', lookup_expr="icontains", label="媒体规格")
    department = filters.CharFilter(field_name='creator_user__user_departments__department_id', label="用户子部门")
    start_date = rest_framework.DateFilter(field_name='add_time', lookup_expr='gte', label="开始时间")
    end_date = rest_framework.DateFilter(field_name='add_time', lookup_expr='lte', label="结束时间")

    class Meta:
        model = MediaContent
        # fields = ('title', 'types', 'sku')
        fields = ('title', 'types', 'department', 'start_date', 'end_date')


class ImageFilter(FilterSet):
    """图库过滤"""
    title = filters.CharFilter(field_name='title', lookup_expr="icontains", label="标签名称")

    class Meta:
        model = Image
        fields = ('title', 'image_label_id','is_image')
